package logic

import (
	"context"
	"fmt"

	"e4ting/internal/svc"
	"e4ting/pb/e4ting"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListAccountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListAccountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListAccountLogic {
	return &ListAccountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListAccountLogic) ListAccount(in *e4ting.SearchRequest) (*e4ting.ManyAccountRes, error) {
	limit,offset,keyword := GetPage(in)
	items, count, err := l.svcCtx.MoneyModel.Search(l.ctx, limit, offset)
	if err != nil {
		return &e4ting.ManyAccountRes{
			Code: 200,
			Err: err.Error(),
		}, nil
	}

	fmt.Printf("%d %d limit=%d,offset=%d,keyword=%s\n", count, len(items), limit,offset, keyword)
	return &e4ting.ManyAccountRes{
		Code: 200,
		Total: count,
		Data: ToAccountList(items),
	}, nil
}
